package com.skyline2yc.databus.controller;

import com.skyline2yc.databus.entity.DataMarket;
import com.skyline2yc.databus.entity.PageResult;
import com.skyline2yc.databus.service.DataMarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/datamarket")
public class DataMarketController {
    @Autowired
    private DataMarketService dataMarketService;

    /**
     * 新建数据集
     */
    @PostMapping("/create")
    public Integer createDataMarket(@RequestParam("datasourceName") String datasourceName,
                                    @RequestParam("datasetName") String datasetName,
                                    @RequestParam("tableName") String tableName,
                                   @RequestParam("serviceName") String serviceName) {
        Integer result = dataMarketService.createDataMarket(datasourceName, datasetName, tableName, serviceName);
        return result;

    }


    /**
     * 分页查询数据集
     */
    @GetMapping("/page")
    public PageResult<DataMarket> pageQyery(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                            @RequestParam(value = "rows", defaultValue = "10") Integer rows,
                                            @RequestParam(value = "key", required = false) String key
    ) {
        PageResult<DataMarket> pageResult = dataMarketService.pageQyery(page, rows, key);
        return pageResult;
    }

    /**
     *
     */
    /**
     * 根据数据集id删除数据集
     */
    @GetMapping("/delete")
    public Integer deleteById(@RequestParam("id") Integer id) {
        Integer result = dataMarketService.deleteById(id);
        return result;
    }

    /**
     * 修改数据集
     */
//    @PostMapping("/update")
//    public Integer updateDataSet(){
//
//    }
}
